<!DOCTYPE html>
<html>
<head>
<title>tinymce.util.LocalStorage tests</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="../../js/qunit/reporter.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/tinymce_loader.js"></script>
<script>
var LocalStorage = tinymce.util.LocalStorage;

module("tinymce.util.LocalStorage", {
	setup: function() {
		LocalStorage.clear();
	},

	teardown: function() {
		LocalStorage.clear();
	}
});

QUnit.config.reorder = false;

test('setItem', function() {
	LocalStorage.setItem("a", "1");
	equal(LocalStorage.getItem("a"), "1");
	LocalStorage.setItem("a", "2");
	equal(LocalStorage.getItem("a"), "2");
	LocalStorage.setItem("a", 3);
	equal(LocalStorage.getItem("a"), "3");
	LocalStorage.setItem("a", null);
	equal(LocalStorage.getItem("a"), "null");
	LocalStorage.setItem("a", undefined);
	equal(LocalStorage.getItem("a"), "undefined");
	LocalStorage.setItem("a", new Date(0));
	equal(LocalStorage.getItem("a"), new Date(0).toString());
});

test('getItem', function() {
	LocalStorage.setItem("a", "1");
	equal(LocalStorage.getItem("a"), "1");
	LocalStorage.setItem("a", "0");
	equal(LocalStorage.getItem("a"), "0");
	equal(LocalStorage.getItem("b"), null);
});

test('removeItem', function() {
	LocalStorage.setItem("a", "1");
	equal(LocalStorage.getItem("a"), "1");
	LocalStorage.removeItem("a");
	equal(LocalStorage.getItem("a"), null);
});

test('key', function() {
	LocalStorage.setItem("a", "1");
	equal(LocalStorage.key(0), "a");
	equal(LocalStorage.length, 1);
});

test('length', function() {
	equal(LocalStorage.length, 0);
	LocalStorage.setItem("a", "1");
	equal(LocalStorage.length, 1);
});

test('clear', function() {
	equal(LocalStorage.length, 0);
	LocalStorage.setItem("a", "1");
	equal(LocalStorage.length, 1);
});

test('setItem key and value with commas', function() {
	LocalStorage.setItem("a,1", "1,2");
	LocalStorage.setItem("b,2", "2,3");
	equal(LocalStorage.getItem("a,1"), "1,2");
	equal(LocalStorage.getItem("b,2"), "2,3");
});

test('setItem with two large values', function() {
	var data = "";

	for (var i = 0; i < 1024; i++) {
		data += 'x';
	}

	LocalStorage.clear();
	LocalStorage.setItem("a", data + "1");
	LocalStorage.setItem("b", data);
	equal(LocalStorage.getItem("a").length, 1024 + 1);
	equal(LocalStorage.getItem("b").length, 1024);
});

test('setItem with two large keys', function() {
	var key = "";

	for (var i = 0; i < 1024; i++) {
		key += 'x';
	}

	LocalStorage.clear();
	LocalStorage.setItem(key + "1", "a");
	LocalStorage.setItem(key + "2", "b");
	equal(LocalStorage.key(0), key + "1");
	equal(LocalStorage.key(1), key + "2");
});
</script>
</head>
<body>
	<h1 id="qunit-header">tinymce.util.Cookie tests</h1>
	<h2 id="qunit-banner"></h2>
	<div id="qunit-testrunner-toolbar"></div>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests"></ol>
	<div id="content"></div>
</body>
</html>
